package com.example.springboot_vue.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springboot_vue.common.PageDto;
import com.example.springboot_vue.entity.RecordEntity;
import com.example.springboot_vue.mapper.RecordMapper;
import com.example.springboot_vue.service.RecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sgp
 * @since 2024-07-22
 */
@Service
public class RecordServiceImpl extends ServiceImpl<RecordMapper, RecordEntity> implements RecordService {

    @Autowired
    private  RecordMapper recordMapper;

    @Override
    public PageDto<RecordEntity> getList(RecordEntity recordEntity) {
        QueryWrapper<RecordEntity> queryWrapper = new QueryWrapper<>();
        if(ObjectUtils.isNotEmpty(recordEntity.getGoods())){
            queryWrapper.lambda().like(RecordEntity::getGoods,recordEntity.getGoods());
        }
        Page<RecordEntity> page = new Page<>(recordEntity.getPage(), recordEntity.getSize());
        Page<RecordEntity> selectPage = recordMapper.select(page, queryWrapper);
        PageDto<RecordEntity> pageDto = new PageDto<>();
        pageDto.setTotal(selectPage.getTotal());
        pageDto.setList(selectPage.getRecords());
        return pageDto;
    }
}
